package com.itheima.dao.system;

import com.itheima.domain.system.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @Author:Mr.yuan
 * @Description:
 * @Date: Created in 22:43 2020/11/29
 * @ModifiedBy:
 */
public interface UserDao {
    /**
     * @Description: 查詢所有用戶
     * @Param: []
     * @return: java.util.List<com.itheima.domain.system.User>
     * @Author: Mr.yuan
     * @Date: 2020/12/1
     */
    @Select("select * from users  ")
    List<User> findAll();

    /**
     * @Description:  通過用戶名和密碼查找用戶
     * @Param: [user]
     * @return: com.itheima.domain.system.User
     * @Author: Mr.yuan
     * @Date: 2020/12/1
     */
    @Select("select * from users where username=#{username} and password=#{password} ")
    User findByUNameAndPWd(User user);

    /**
     * @Description:  通過id查找用戶
     * @Param: [id]
     * @return: com.itheima.domain.system.User
     * @Author: Mr.yuan
     * @Date: 2020/12/1
     */
    @Select("select * from users where id=#{id}")
    User findById(String id);


    /**
     * @Description:  通過id更新用戶密碼
     * @Param: [user]
     * @return: void
     * @Author: Mr.yuan
     * @Date: 2020/12/1
     */
    @Select("update users set password=#{password} where id=#{id}")
    void updatePWD(User user);

    /**
     * @Description: 根据用户名称模糊查询所有
     * @Param:[username]
     * @return:java.util.List<com.itheima.domain.system.User>
     * @Author:Mr.Cheng
     * @Date:2020/11/30
     */
    List<User> findAllByUserNameLike(@Param("username") String username);

    /**
     * @Description: 新增用户
     * @Param:[user]
     * @return:void
     * @Author:Mr.Cheng
     * @Date:2020/11/30
     */
    void save(User user);

    /**
     * @Description: 批量删除用户
     * @Param:[userId]
     * @return:void
     * @Author:Mr.Cheng
     * @Date:2020/11/30
     */
    void delete(@Param("userId") String userId);

    /**
     * @Description: 根据id查找用户
     * @Param:[userId]
     * @return:com.itheima.domain.system.User
     * @Author:Mr.Cheng
     * @Date:2020/11/30
     */
    User findByUserId(String userId);

    /**
     * @Description: 根据id查找用户属性
     * @Param:[userId]
     * @return:java.util.List<java.util.Map>
     * @Author:Mr.Cheng
     * @Date:2020/11/30
     */
    List<Map> findAllRoleByUserId(@Param("userId") String userId);

    /**
     * @Description: 根据 用户id 删除 该用户 映射的 所有 权限信息
     * @Param:[userId]
     * @return:void
     * @Author:Mr.Cheng
     * @Date:2020/11/30
     */
    void deleteUsersRoleByUserId(String userId);

    /**
     * @Description: 将配置好的用户属性进行保存
     * @Param:[roleIds, userId]
     * @return:void
     * @Author:Mr.Cheng
     * @Date:2020/11/30
     */
    void saveRoleToUser(@Param("roleId") String roleId, @Param("userId") String userId);

    /**
     * @Description: 修改用户
     * @Param:[users]
     * @return:void
     * @Author:Mr.Cheng
     * @Date:2020/11/30
     */
    void update(User users);

    /**
     * @Description: 通過手機號查詢用戶
     * @Param: [phoneNum]
     * @return: com.itheima.domain.system.User
     * @Author: Mr.yuan
     * @Date: 2020/12/1
     */
    @Select("select * from users where phoneNum=#{phoneNum}")
    User findByPhoneNum(String phoneNum);

    List<String> findAllPermissionUrlByUserId(String userId);
}
